home *** CD-ROM | disk | FTP | other *** search
- /* © Copyright 1990,1991 The NetWork Project, StatLab Heidelberg. All rights reserved. */
- /* © Copyright 1990,1991 Joachim Lindenberg, Karlsruhe. All rights reserved. */
-
- /* This tool demonstrates that you can
- - use NetWork from C (the interfaces are yet incomplete and are subject to change)
- - use SIOW based IO that allows your tool to run within and outside the MPW environment
-
- Currently, this tool simply gets, accepts, and destroys incoming messages.
-
- Note: This program only works because of the getchar() at the end !!!
- Output may be garbled if messages arrive too fast.
- */
-
- #include <Types.h>
- #include <Events.h>
- #include <stdio.h>
- #include <NetWork.h>
-
- #define NetWorkEvent networkEvt
-
- void HandleMsg (MsgPtr msg)
- {
- if ((msg->MsgResult < 0) || (msg->MsgCmd & tMinorMask >= tTimeout)) DestroyMsg (msg);
- else switch (msg->MsgCmd & tMajorMask) {
- case tListen : printf ("got something\n"); fflush (stdout);
- GetMsg (msg, NULL, 0); AcceptMsg (msg, NULL, 0); break;
- case tAccept : DestroyMsg (msg); break;
- case tPost : DestroyMsg (msg); break;
- };
- };
-
- Boolean Filter (EventRecord *ev)
- {
- if (ev->what == NetWorkEvent) {
- HandleMsg ((MsgPtr) ev->message);
- return (true);
- }
- return (false);
- }
- extern long __siowEventHook; /* this hook is called by SIOW with every event */
-
- main (argc, argv)
- int argc; char **argv;
- {
- printf ("Hello.\n\n");
- printf ("This program demonstrates how simple it is to use a tool based approach\n\n");
- fflush (stdout);
-
- InitNetWork (NetWorkEvent);
- __siowEventHook = Filter;
- while (getchar () != '\n') ;
- ExitNetWork ();
- }
-
-
-